﻿using Framework.Cache;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MonitorCode;
using MonitorCode.DBCode;
using MonitorCode.Hangfire;
using MonitorCode.Models;
using Support.Models;
using Support.Models.Dto;
using Support.Models.Entities;
using System;
using YouShuCode;

namespace DevSupport.Areas.Monitor
{ 
    [ApiController]
    public class ChartDataController : ControllerBase
    {
        private ILogger<ChartDataController> _logger;
        private readonly IMonitorDataService _monitorDataService;

        public ChartDataController(ILogger<ChartDataController> logger, IMonitorDataService monitorDataService)
        {
            _logger = logger;
            _monitorDataService = monitorDataService;
        }
        /// <summary>
        /// 监控面板模拟数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/ChartData/GetMockData")]
        public async Task<TData> GetMockData()
        {
            return await _monitorDataService.GetMockData();
        }
        /// <summary>
        /// 获取监控面板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/ChartData/GetMonitorResult")]
        public async Task<TData> GetMonitorResult()
        { 
            return await _monitorDataService.GetMonitorResult(); 
        }
        /// <summary>
        /// 删除数据监控
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        [Route("api/MonitorData/DeleteChartJob")]
        public async Task<TData> DeleteChartJob(string jobId)
        { 
            return await _monitorDataService.DeleteJobMonitorFire(jobId); 
        }

        /// <summary>
        /// 数据监控列表
        /// </summary>
        /// <param name="keyword">关键字搜索</param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/MonitorData/GetJobList")]
        public async Task<object> GetJobMonitorDataListAsync(string? keyword = "")
        {
            return await _monitorDataService.GetJobFireMonitorDataListAsync(keyword);
        }
        /// <summary>
        /// 添加服务hangfirejob
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/MonitorData/AddJob")]
        public async Task<TData> AddMonitorDataJob(Job_MonitorData dto)
        {
            return await _monitorDataService.AddJobMonitorFire(dto);
        }
        /// <summary>
        /// 开启服务监控
        /// </summary>
        /// <param name="JobId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/MonitorData/StartJob")]
        public async Task<TData> StartJobMonitorDataAsync(string JobId)
        {
            return await _monitorDataService.StartJobMonitorFireAsync(JobId);
        }
        /// <summary>
        /// 停止服务监控
        /// </summary>
        /// <param name="JobId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/MonitorData/StopJob")]
        public TData StopJobMonitorDataAsync(string JobId)
        {
            return _monitorDataService.StopJobMonitorFire(JobId);
        }
    }
}
